import smtplib
import ssl
from email.message import EmailMessage

EMAIL_ADDRESS = "qq958538206@163.com"  # 邮箱的地址
EMAIL_PASSWORD = "MVKAGLELBSMEFUDM"  # 授权码


context = ssl.create_default_context()

subject = "你将收到1000条该短信"
body = "马龙你好邀请你参加乒乓球比赛"

msg = EmailMessage()
msg['subject'] = subject  # 邮件标题
msg['From'] = EMAIL_ADDRESS  # 邮件发件人
msg['To'] = "15517943307@163.com"  # 邮件的收件人
msg.set_content(body)  # 使用set_content()方法设置邮件的主体内容

# 为了防止忘记关闭连接也可以使用with语句
with smtplib.SMTP_SSL("smtp.163.com", 465, context=context) as smtp:  # 完成加密通讯

    # 连接成功后使用login方法登录自己的邮箱
    smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)

    '''
    # 方式一：
    # 使用 sendmail 方法实现发送邮件信息
    sender = EMAIL_ADDRESS      # 邮件发件人
    receive = EMAIL_ADDRESS       # 邮件收件人
    subject = "subject"
    body = "body"
    msg = f"Subject: {subject}\n\n{body}"
    print("正在发送。。。。。。。。。。。。。。。。。。")
    smtp.sendmail(sender, receive, msg)
    print("发送成功。。。。。。。。。。。。。。。。。。")
    '''

    # 方式二：使用send_message方法发送邮件信息
    smtp.send_message(msg)


